import { Context, Session } from 'koishi'
import AllPlantList from "../../utils/plantList";
import { handlePlant } from "../../database/userList";

const keyWordList = [
    {
        name: ' 种植植物',
        // 正则 格式为 种xxx个xxx xxx可能是数字或字符串 如种一百二十个豌豆 种12个向日葵 种个小喷
        reg: /种?([\u4e00-\u9fa50-9]+)个([\u4e00-\u9fa5]+)/,
        fn: (messageData: any, ctx: Context, session: Session) => {
            const content = messageData.message.content
            const userId = messageData.user.id
            let number = content.split('个')[0].split('种')[1]
            number = number ? number : 1
            const plantName = content.split('个')[1]
            const plantList = AllPlantList()
            const targetPlant = plantList.find((plant) => plant.alias.includes(plantName))
            if (targetPlant) {
                handlePlant(ctx, userId, number, targetPlant.id)
            }
        }
    }
]


export default keyWordList